/**
 * Copyright (C) 2009 aileron.cc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cc.aileron.orm;

import static cc.aileron.orm.G2DaoFindCondition.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;

import cc.aileron.junit.runner.guice.GuiceInjectRunner;
import cc.aileron.junit.runner.guice.GuiceInjectRunnerModule;
import cc.aileron.orm.G2DaoFindCondition.Paging;
import cc.aileron.orm.sample.SampleEntity;

import com.google.inject.Inject;

/**
 * とりあえず、試してみる
 * 
 * @author Aileron
 */
@GuiceInjectRunnerModule(TryModule.class)
@RunWith(GuiceInjectRunner.class)
public class TryOrm
{

    /**
     * try create
     */
    @Test
    public void create()
    {
        for (int i = 1, max = 100; i < max; i++)
        {
            final SampleEntity entity = new SampleEntity();
            entity.id = i;
            entity.content = "test";
            dao.insert(entity);
        }

        final Paging paging = new Paging(50);
        paging.page = 0;
        assertThat(dao.findList(all, new Paging(50, 0)).size(), is(50));

        paging.page = 1;
        assertThat(dao.findList(all, paging).size(), is(50));

        paging.page = 2;
        assertThat(dao.findList(all, paging).size(), is(0));
    }

    /**
     * @param daoManager
     */
    @Inject
    public TryOrm(final G2DaoManager daoManager)
    {
        dao = daoManager.get(SampleEntity.class);
    }

    private final G2Dao<SampleEntity> dao;
}